package com.example.cupid.util;

import com.example.cupid.pojo.Wechat;

import java.util.List;

/**
 * 2021/9/17
 **/
public class MsgUtil {
    public static Wechat msgToWechat(String passback_params){
        Wechat wechat = new Wechat();
        String wechatStr = passback_params.substring(passback_params.indexOf("(")+1, passback_params.indexOf(")"));
        String[] list = wechatStr.split(", ");
        for (String item : list) {
            String key = item.substring(0, item.indexOf("="));
            String value = item.substring(item.indexOf("=") + 1);
            switch (key) {
                case "id":
                    wechat.setId(Integer.parseInt(value));
                    break;
                case "wechat":
                    wechat.setWechat(value);
                    break;
                case "sex":
                    wechat.setSex(Integer.parseInt(value));
                    break;
                case "school":
                    wechat.setSchool(value);
                    break;
                case "grade":
                    wechat.setGrade(value);
                    break;
                case "description":
                    wechat.setDescription(value);
                    break;
                default:break;
            }
        }
        return wechat;
    }
    public static String[] msgToTags(String passback_params){
        return passback_params.substring(passback_params.indexOf("[")+1, passback_params.indexOf("]")).split(", ");
    }
    public static Integer msgToUserId(String passback_params){
        String id = passback_params.substring(0, passback_params.indexOf("W"));
        return Integer.parseInt(id);
    }
}
